package com.atguigu.tingshu.payment.api;

import com.atguigu.tingshu.common.login.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.payment.service.WxPayService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Tag(name = "微信支付接口")
@RestController
@RequestMapping("api/payment")
@Slf4j
public class WxPayApiController {

    @Autowired
    private WxPayService wxPayService;


    /**
     * 创建微信支付订单
     * @param paymentType 1301:下单 1302：充值
     * @return {timeStamp:"",package:"",paySign:"",signType:"",nonceStr:""}
     */
    @GuiGuLogin
    @Operation(summary = "对接微信支付，获取小程序拉起微信支付所需参数")
    @PostMapping("/wxPay/createJsapi/{paymentType}/{orderNo}")
    public Result<Map<String, String>> createJsapi(@PathVariable String paymentType, @PathVariable String orderNo){
        Map<String, String> map = wxPayService.createJsapi(paymentType, orderNo);
        return Result.ok(map);
    }

    /**
     * 查询订单支付状态
     * @param orderNo
     * @return true:已支付  false:未支付
     */
    @GuiGuLogin
    @Operation(summary = "商户测主动查询订单支付状态")
    @GetMapping("/wxPay/queryPayStatus/{orderNo}")
    public Result<Boolean> queryPayStatus(@PathVariable String orderNo){
        boolean result = wxPayService.queryPayStatus(orderNo);
        return Result.ok(result);
    }


    /**
     * 微信支付成功后，微信支付会主动调用商户通知支付结果
     * @return
     */
   /* @Operation(summary = "用户微信支付成功后，微信支付会主动调用商户通知支付结果")
    @PostMapping("/wxPay/notify")
    public Result wxPaySuccessNotify(HttpServletRequest request){
        wxPayService.wxPaySuccessNotify(request);
        return Result.build(null, 200, "SUCCESS");
    }*/

}
